﻿/**
*发放意向书编号
*/
Chenxin.UI.LetterCodeIssueForm = Chenxin.extend(Chenxin.UI.FormCommon,{
    actionUrl:'/service/logic/ShowListIntent.ashx',
    id:'Issue',
    renderTo:'divIssue',
    winCls:'',
    jqmWidth:560,
    defBBtn:true,
	show:function(){
		$('#tr_code_year_select').hide();
		$('.tr_intentiontype').show();
		return Chenxin.UI.LetterCodeIssueForm.superclass.show.call(this);
	},
    createForm: function() {
        return Chenxin.FormCommon.LetterCodeIssueForm(this.id);
    },
    loadinfo: function() {
        var _this = this;
        var _mode=this.getParam();
        if(!_mode.companyid){
            alert('请选择公司！');
            return;
        }
        delete _mode.IntentionCode;
        delete _mode.CodeCount;
		
		var _data={op: 'getcode'};
		Chenxin.apply(_data,_mode);
		if(this.additionalParam.code_year){
			_data.code_year=this.additionalParam.code_year;
		} 
		
		Chenxin.Msg.Waiting.show();
        Chenxin.ajax({
            type: "post",
            dataType: "text",
            paramType: 'json',
            async:false,
            url: '/service/logic/ShowListIntent.ashx',
            data:_data,
            onSuccess: function(data, msg) {
				Chenxin.Msg.Waiting.hide();
                if (data) {
                    _this.findByName('IntentionCode').val(data.IntentionCode);
                }
            },
			onFail:function(){
				Chenxin.Msg.Waiting.hide();			
			},
			onWrong:function(){
				Chenxin.Msg.Waiting.hide();		
			},
			onError:function(){
				Chenxin.Msg.Waiting.hide();			
			}
        });
    },
	initFormValidator:function(){
        //发放数量
        $("#CodeCount").formValidator({
            validatorgroup: this.id,
            onshow: "请输入发放数量！",
            onfocus: "数量不可超过10份！",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "发放数量不能为空！"
            },
            onerror: "发放数量不能为空！"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                val = Chenxin.Fn.fullToHalfChar(val);
                if (parseInt(val) <= 0 || parseInt(val) > 10) {
                    return false;
                }
                else {
                    return val.isNum();
                }
            },
            onerror: "请输入非0,且小于10的整数"
        });
    },
    createComboList:function(){
        //五级联Combo
		var _this=this;
        var combl = new Chenxin.UI.StructComboList({
            comboContainerId:{
		        city:'#city_1',
		        company:'#company_1',
		        businessDistrict:'#businessdistrict_1',
		        departs:'#departs_1',
		        employee:'#employee_1'
	        },
	        inModelType:'all',
			tbxWidth:70,
	        comboTxtModelNameConfig:{
			    city:'city',
			    company:'company',
			    businessDistrict:'area',
			    departs:'depart',
			    employee:'user'			
		    },
			cityAfterSelected:function(){
				_this.resetCode();
			},
			companyAfterSelected:function(){
				_this.resetCode();
			}
        });
        var structs = combl.comboList;
        return structs;
    },
    initEvent: function() {
        var _this = this;
        var thisid='#'+this.id;	
		_this.isclick = true;
		
		$(thisid+'_save').live('click',function(){			
		    if(_this.isclick)
		    {
			    _this.save();
			}
		});
		$(thisid+'_cancle').live('click',function(){			
			_this.hide();
		});
		
		$('#btn_getcode').live('click',function(){
            _this.loadinfo();
		});
		this.findByName('BusinessType').bind('click',function(){
			$('.tr_intentiontype')[this.value=='10'?'show':'hide']();
			_this.resetCode();
		});
		this.findByName('code_year_type').bind('click',function(){
			$('#tr_code_year_select')[this.value=='20'?'show':'hide']();
			_this.resetCode();
		});
		this.findByName('IntentionType').bind('click',function(){
			_this.resetCode();
		});
    },
	resetCode:function(){
		this.findByName('IntentionCode').val('');
		this.findByName('CodeCount').val('');
	},
    saveSucc: function() {
        this.reloadGrid();
    },
	initCodeYear:function(){
        var _this = this;
		var d=new Date();
		var _year=d.getFullYear();
		var _td=$('#tr_code_year_select').find('td');
		for(var i=0;i<5;i++){
			_td.append('<input type="radio" name="code_year" value="'+(_year-i)+'" id="r_cys_'+i+'" title="'+(_year-i)+'年"/><label for="r_cys_'+i+'">'+(_year-i)+'</label>');
		}
		this.findByName('code_year').bind('click',function(){
			_this.resetCode();
		})
	},
    initComponent: function() {
        Chenxin.UI.LetterCodeIssueForm.superclass.initComponent.call(this);
		this.initCodeYear();
    }
});

Chenxin.FormCommon.LetterCodeIssueForm=function(formID){
return '<table class="tbl_f jqTabWh"><tr><th style="width:100px;">业务类型：</th><td colspan="3"><input type="hidden"  name="IntentionId" /><input type="radio" value="10" name="BusinessType" checked="checked"/>买卖<input type="radio" value="20" name="BusinessType" />租赁</td></tr><tr class="tr_intentiontype"><th>意向书类型：</th><td colspan="3"><input type="radio" value="10" name="IntentionType" checked="checked"/>买卖协议<input type="radio" value="20" name="IntentionType" />居间协议</td></tr><tr><th>城市：</th><td><div id="city_1" style="z-index:3; margin-right: 2px;" class="SelectWrapSingle"></div></td><th style="width:100px;">公司：</th><td><div id="company_1" style="z-index:3; margin-right: 2px;" class="SelectWrapSingle"></div></td></tr><tr><th>商圈：</th><td><div id="businessdistrict_1" style="z-index:2; margin-right: 2px;" class="SelectWrapSingle"></div></td><th>部门：</th><td><div id="departs_1" style="z-index:2; margin-right: 2px;" class="SelectWrapSingle"></div></td></tr><tr><th>人员：</th><td><div id="employee_1"style="z-index:1; margin-right: 2px;" class="SelectWrapSingle"></div></td></tr><tr><th>编号年限：</th><td colspan="3"><input type="radio" name="code_year_type" value="10"/>使用本年度编号<input type="radio" name="code_year_type" value="20"/>重新选择年限</td></tr><tr id="tr_code_year_select" style="display:none;"><th>年限：</th><td colspan="3"></td></tr><tr><th>起始编号：</th><td colspan="3"><input name="IntentionCode" class="inputbox_n fl" type="text" readonly="readonly" style="width:100px;"/><input type="button" id="btn_getcode" value="获取起始编号"  style="margin-left:10px;" title="获取起始编号"/></td></tr><tr><th>发放数量：</th><td colspan="3"><input name="CodeCount" id="CodeCount" class="inputbox_n fl" type="text" style="width:100px;"/><div id="CodeCountTip" style="margin-left: 5px; width: 160px; float:left;text-align: left;" class="fl"></div></td></tr></table>';
};